mir: Fix potential use of NULL GDBusConnection
authorPhilip Withnall <withnall@endlessm.com>
Fri, 17 Nov 2017 10:32:02 +0000 (10:32 +0000)
committerPhilip Withnall <withnall@endlessm.com>
Fri, 8 Dec 2017 09:55:27 +0000 (09:55 +0000)
If we fail to connect to the session bus, it would be a bit silly to
immediately try and use that NULL connection.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
https://bugzilla.gnome.org/show_bug.cgi?id=668590

gdk/mir/gdkmirdisplay.c

index bedb1524a9bc3a18bc577778cf35d3ff3500918a..1086d62173acf8cc201cdb61e5a486dc4166fa3a 100644 (file)
@@ -176,6 +176,7 @@ _gdk_mir_display_open (const gchar *display_name)
   MirPixelFormat sw_pixel_format, hw_pixel_format;
   GdkMirDisplay *display;
   GDBusConnection *session;
+  GError *error = NULL;
 
   connection = mir_connect_sync (NULL, g_get_prgname ());
   if (!connection)
@@ -208,7 +209,15 @@ _gdk_mir_display_open (const gchar *display_name)
   display->sw_pixel_format = sw_pixel_format;
   display->hw_pixel_format = hw_pixel_format;
 
-  session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+  session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+
+  if (session == NULL)
+    {
+      g_error ("Error connecting to D-Bus session bus: %s", error->message);
+      g_clear_error (&error);
+      mir_connection_release (connection);
+      return NULL;
+    }
 
   display->content_service = content_hub_service_proxy_new_sync (
     session,